package com.ts.proj.service.impl;

import com.ts.base.service.impl.CommonServiceImpl;
import com.ts.proj.entity.JijinItemEntity;
import com.ts.proj.repository.JijinItemRepository;
import com.ts.proj.service.JijinItemService;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


//说明 字符串：，作为替换字符串 LOWERFinance                Finance

@Service
public class JijinItemServiceImpl extends CommonServiceImpl<JijinItemEntity>  implements JijinItemService {

    @Autowired
    private JijinItemRepository jijinItemRepository;

    @Override
    public List<JijinItemEntity> findAll(PageData pageData, Integer start, Integer length) {
        Specification<JijinItemEntity> sp = this.getSpecification(pageData,JijinItemEntity.class);
        Sort sort = new Sort(Sort.Direction.ASC,"id");
        Pageable pageable = new PageRequest(start, length, sort);
        return jijinItemRepository.findAll(sp,pageable).getContent();
    }

    @Override
    public long count(PageData pageData) {
        Specification<JijinItemEntity> sp = this.getSpecification(pageData,JijinItemEntity.class);
        return jijinItemRepository.count(sp);
    }

    @Override
    public boolean deleteByIds(Iterable<JijinItemEntity> iterable) {
        jijinItemRepository.deleteInBatch(iterable);
        return false;
    }

    @Override
    public List<JijinItemEntity> saveAll(List<JijinItemEntity> entities) {
        return jijinItemRepository.saveAll(entities);
    }

    @Override
    public List<JijinItemEntity> findAllById(Integer[] ids) {
        List<JijinItemEntity> list = jijinItemRepository.findAllById(Arrays.asList(ids));
        if(list.size()==0){
            JijinItemEntity entity = new JijinItemEntity();
            list.add(entity);
        }
        return list;
    }

    @Override
    public boolean deleteAll() {
        jijinItemRepository.deleteAll();
        return false;
    }
}